#include "TestGame.h"

const int FRAME_RATE = 60;

TestGame::TestGame(HINSTANCE hInstance, int nCmdShow, D3DDEVTYPE devType, DWORD requestedVP) : Application(hInstance, nCmdShow, devType, requestedVP) 
{
	//Initialize and Creates the instances for previewing and render a screen
	m_Manager = new ScreenManager();
	m_Manager->setScreen(new CollisionTestScreen());
	m_pCurrentScreen = m_Manager->getCurrentScreen();
}

TestGame::~TestGame()
{
}


void TestGame::onLostDevice() 
{
	m_pCurrentScreen->onLostDevice();
}

void TestGame::onResetDevice() 
{
	m_pCurrentScreen->onResetDevice();
}

void TestGame::renderScene() 
{
	//Clears the screen to a black background
	HR(g_pD3DDevice->Clear(NULL, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, NULL));

	//Starts the rendering process of a scene using Direct3D device
	HR(g_pD3DDevice->BeginScene());

	//Renders the current screen
	m_pCurrentScreen->renderScreen();

	//Stops the rendering process for the Direct3D device
	HR(g_pD3DDevice->EndScene());

	//Tosses the screen from the back buffer to the front buffer
	HR(g_pD3DDevice->Present(0, 0, 0, 0));
}

void TestGame::updateScene(float dt) {

	//Holds the number of frames
	static float		timeElapsed		= 0.00f;

	//Increment the time that has passed in order to
	//access the contents inside the game loop
	timeElapsed += dt;

	//Provides the information regarding the screen to update within
	//the engine environment
	m_pCurrentScreen->updateScreen(dt);
	
	if(timeElapsed >= (1.0f / FRAME_RATE)) {
		
		//Set the timer back to zero
		timeElapsed = 0.00f;
	}
}